1. /* spltlgfl.cpp by K.Tsuru */
  2. /*
  3. Split the decimal part of large number file in the form
  4. 3.+
  5. 1415...
  6. exsample large file name lines out file
  7. SplitLargeFile("ChudnovskysPi[1billion].dat", 1000000,"ChudPi%02d.dat");
  8. */
  9. #include <stdlib.h>
  10. #include <fstream>
  11. #include <string.h>
  12. using namespace std;
  13. int SplitLargeFile(const char* largeFileName, const long fileLineUnit, const char* outFNameFormat)
  14. {
  15. const int buffLength = 500;
  16. char splitFname[257], buff[buffLength];
  17. bool point = false; // decimal point
  18. ifstream read(largeFileName, ios::in);
  19. while(!point && !read.eof()) { // search point '.'
  20. read.getline(buff, buffLength, '\n');
  21. if(strchr(buff, '.')) point = true;
  22. }
  23. if(!point) return -1; // not decimal file
  24. ofstream fout;
  25. int fNo = 1, line = 1;
  26. while(!read.eof()) {
  27. sprintf(splitFname, outFNameFormat, fNo);
  28. fout.open(splitFname, ios::out);
  29. do { // write one block(a split file)
  30. read.getline(buff, buffLength, '\n');
  31. fout << buff << endl; line++;
  32. if(line > fileLineUnit){
  33. line = 1; fNo++;
  34. fout.close(); break;
  35. }
  36. } while(strlen(buff));
  37. }
  38. return fNo;
  39. }

spltlgfl.cpp : last modifiled at 2017/06/20 15:39:04(1,182 bytes)
created at 2017/10/03 15:04:05
The creation time of this html file is 2017/10/07 10:54:16 (Sat Oct 07 10:54:16 2017).